package com.tyk.bookstore.front.comment.controller;


import com.tyk.bookstore.front.comment.model.query.ReplyAddQuery;
import com.tyk.bookstore.front.comment.model.query.ReplyPageQuery;
import com.tyk.bookstore.front.comment.model.vo.ReplyPageVo;
import com.tyk.bookstore.front.comment.service.ReplyService;
import com.tyk.bookstore.front.common.core.model.result.R;
import com.tyk.bookstore.front.common.core.model.vo.PageVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author tyk
 * @description 评论管理
 */
@RequestMapping({"api/message/reply"})
@Tag(name = "评论管理/回复管理", description = "回复管理")
@RestController
@RequiredArgsConstructor
public class ReplyController {

    private final ReplyService replyService;

    @PostMapping
    @Operation(summary = "回复评论/回复", description = "回复评论/回复")
    public R<Object> add(
            @Validated @RequestBody ReplyAddQuery query
    ) {
        replyService.add(query);
        return R.ok();
    }

    @GetMapping({"page"})
    @Operation(summary = "分页查询回复", description = "分页查询回复")
    public R<ReplyPageVo> getPage(
            @Validated @ParameterObject ReplyPageQuery query,
            BindingResult br
    ) {
        return br.hasErrors() ? R.ok(PageVo.instance(ReplyPageVo.class)) : R.ok(replyService.getPage(query));
    }

    @DeleteMapping({"{id}"})
    @Operation(summary = "删除回复", description = "删除回复")
    public R<Object> deleteById(
            @Schema(description = "评论ID") @NotNull @Min(1)
            @PathVariable Long id
    ) {
        replyService.deleteById(id);
        return R.ok();
    }


}
